/*
 * @lc app=leetcode.cn id=844 lang=javascript
 *
 * [844] 比较含退格的字符串
 */

// @lc code=start
/**
 * @param {string} s
 * @param {string} t
 * @return {boolean}
 */

var format = function (s) {
  const stack = []
  s.split('').forEach(ch => {
    ch === '#' ? stack.pop() : stack.push(ch);
  })
  return stack.join('')
}
var backspaceCompare = function (s, t) {
  return format(s) === format(t);
};
// @lc code=end
